Added Validator to WarpSyncProvider#10223
Conversation
d3b5b26 to
2ef715e
Compare
bkchr
left a comment
There was a problem hiding this comment.
Thank you for the pull request!
Sorry for the delay until you got this review. See my comment on what needs to be changed. The general idea of the pull request is fine, but the implementation needs to be changed a little bit.
| } | ||
|
|
||
| /// Warp sync backend. Handles retrieving and verifying warp sync proofs. | ||
| pub trait WarpSyncProvider<Block: BlockT>: Send + Sync { |
There was a problem hiding this comment.
We should not introduce the Context type. This requires too many changes that are not really required.
I think we should change the WarpSyncProvider trait in the following way:
- Remove
verifyandcurrent_context. - Introduce a new
create_verifier() -> Arc<Verifier>(maybe you come up with a better name).
trait Verifier<Block> {
fn verify(proof) -> Result;
/// Returns the context in which the verifier operates
fn context() -> Block::Hash;
}
context()for now will always return the genesis hash.last_hashcan then replaced with calls tocontext().
This way we don't require the pass through of the generic parameter to everywhere and also prepare the trait for the future.
efba492 to
7d5cc5c
Compare
| pub struct WarpSync<B: BlockT, Client> { | ||
| phase: Phase<B>, | ||
| client: Arc<Client>, | ||
| _client: Arc<Client>, |
There was a problem hiding this comment.
after lates changes, this client is only used in new function, but I left it to not adjust the interfaces elsewhere. Please let me know if we want to provide some phantom here, remove it or leave or something else
There was a problem hiding this comment.
Let's remove it. We still need client in new. So, we don't need to change any interfaces, but we don't need to store it here.
|
Thank you @bkchr! It simplified this code significantly, I will appreciate if you will allocate some time to make a second round of review, meanwhile I will prepare some prdoc. |
| .ok_or_else(|| "Empty proof".to_string())?; | ||
| let (next_set_id, next_authorities) = | ||
| proof.verify(set_id, authorities, &self.hard_forks).map_err(Box::new)?; | ||
| let (_next_set_id, _next_authorities) = proof |
There was a problem hiding this comment.
here is a interior mutability case that is still not solved, I will take a look later
There was a problem hiding this comment.
I am also curious how the CI tests passed, looks like none of the tests is rotating committee?
bkchr
left a comment
There was a problem hiding this comment.
Just some last nitpicks, otherwise looks good!
| pub struct WarpSync<B: BlockT, Client> { | ||
| phase: Phase<B>, | ||
| client: Arc<Client>, | ||
| _client: Arc<Client>, |
There was a problem hiding this comment.
Let's remove it. We still need client in new. So, we don't need to change any interfaces, but we don't need to store it here.
| *authorities = new_authorities; | ||
| Ok(VerificationResult::Partial(new_last_hash, proofs)) => { | ||
| debug!(target: LOG_TARGET, "Verified partial proof"); | ||
| *last_hash = new_last_hash; |
There was a problem hiding this comment.
Can we just remove last_hash completely and let verifier.context always return the latest hash. Maybe let's rename context to something like next_proof_context or something along these lines.
| }) | ||
| .collect::<Vec<_>>(); | ||
| { | ||
| let mut state = self.state.lock(); |
There was a problem hiding this comment.
The state might become inconsistent, since there's a possibly large gap between the acquired locks. Is this a scenario that can happen within our code?
-T0: [thread 0] first .lock
-T1: [thread 1] first .lock
-T2: [thread 1] complets verifying and sets [next_auth 1, last_header 1]
-T3: [thread 0] complets verifying but now we are overwritting the sets set at T2
There was a problem hiding this comment.
6e35423
Thank you, I made it scoped. My first thought was that this process is synchronous by default, introduction of Mutex/RefCell is for immutability
bkchr
left a comment
There was a problem hiding this comment.
Yeah last change and then we can merge this.
| proof.verify(set_id, authorities, &self.hard_forks).map_err(Box::new)?; | ||
|
|
||
| { | ||
| let mut state = self.state.lock(); |
There was a problem hiding this comment.
Just let's make verify take &mut self. We don't really need the mutex here.
|
Please also merge master, there are some fixes for some of the flaky CI jobs. |
|
Thank you. @bkchr if you could also take a look on this one: #10223 (comment), looks like there is some missing test for warp with rotating committee, due at the moment when this comment was created, validator was not persisting new authority set and CI was green. Maybe it can be addressed in some follow-up issue |
lexnv
left a comment
There was a problem hiding this comment.
LGTM! Thanks for contributing 🙏
310625d
Description
It looks like WarpSyncProvider in
sc-network-synchas direct dependency tosp-consensus-gradnpatypes, speciallySetIdandAuthorityList:This PR is removing this dependency and replaces it with
Validator, which can be used to validate proofs.